package com.keter.checker;

import com.keter.checker.model.Target;
import com.keter.checker.service.CheckerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.Map;

/** Spring Boot 应用的入口文件 */
@SpringBootApplication
public class CheckerStart implements CommandLineRunner {
  private static final Logger logger = LoggerFactory.getLogger(CheckerStart.class);

  @Autowired CheckerService checkerService;

  @Value("${targets.baseUrl}")
  private String[] url;

  public static void main(String[] args) {
      SpringApplication.run(CheckerStart.class, args);
  }

  @Override
  public void run(String... args) throws InterruptedException {

    Map<Integer, Target> results = checkerService.check(url);
    logger.info("------------------- 请求全部执行完成，结果: ----------------\n{}",results);

//    for (int i = 0; i < 5; i++) {
//      Map<String, Target> results = checkerService.check(url);
//      logger.info("------------------- 请求全部执行完成，结果: ----------------\n{}",results);
//      Thread.sleep(1000);
//    }

    System.exit(0);
  }
}
